/**
 * @fileOverview The "basicstyles" plugin.
 */
VED.plugins.add( 'basicstyles', {
   lang: 'en,ru', // %REMOVE_LINE_CORE%
   icons: 'bold,italic,underline,strike,subscript,superscript,blockh1,blockh2,blockh3,blockh4,blockh5,blockh6', // %REMOVE_LINE_CORE%
   hidpi: true, // %REMOVE_LINE_CORE%
   init: function( editor ) {
      var order = 0;
      // All buttons use the same code to register. So, to avoid
      // duplications, let's use this tool function.
      var addButtonCommand = function( buttonName, buttonLabel, commandName, styleDefiniton ) {
         // Disable the command if no definition is configured.
         if ( !styleDefiniton )
            return;

         var style = new VED.style( styleDefiniton ),
             forms = contentForms[ commandName ] || [];

         // Put the style as the most important form.
         forms.unshift( style );

         // Listen to contextual style activation.
         editor.attachStyleStateChange( style, function( state ) {
            !editor.readOnly && editor.getCommand( commandName ).setState( state );
         });

         // Create the command that can be used to apply the style.
         editor.addCommand( commandName, new VED.styleCommand( style, {
            contentForms: forms
         }));

         // Register the button, if the button plugin is loaded.
         if ( editor.ui.addButton ) {
            editor.ui.addButton( buttonName, {
               label: buttonLabel,
               command: commandName,
               toolbar: 'basicstyles,' + ( order += 10 )
            });
         }
      };

      var contentForms = {
            bold: [
               'strong',
               'b',
               [ 'span', function( el ) {
                  var fw = el.styles[ 'font-weight' ];
                  return fw == 'bold' || +fw >= 700;
               } ]
            ],

            italic: [
               'em',
               'i',
               [ 'span', function( el ) {
                  return el.styles[ 'font-style' ] == 'italic';
               } ]
            ],

            underline: [
               'u',
               [ 'span', function( el ) {
                  return el.styles[ 'text-decoration' ] == 'underline';
               } ]
            ],

            strike: [
               's',
               'strike',
               [ 'span', function( el ) {
                  return el.styles[ 'text-decoration' ] == 'line-through';
               } ]
            ],

            subscript: [
               'sub'
            ],

            superscript: [
               'sup'
            ]
         },
         config = editor.config,
         lang = editor.lang.basicstyles;

      addButtonCommand( 'Bold', lang.bold, 'bold', config.coreStyles_bold );
      addButtonCommand( 'Italic', lang.italic, 'italic', config.coreStyles_italic );
      addButtonCommand( 'Underline', lang.underline, 'underline', config.coreStyles_underline );
      // addButtonCommand( 'Strike', lang.strike, 'strike', config.coreStyles_strike );
      // addButtonCommand( 'Subscript', lang.subscript, 'subscript', config.coreStyles_subscript );
      // addButtonCommand( 'Superscript', lang.superscript, 'superscript', config.coreStyles_superscript );

      addButtonCommand( 'BlockH1', lang.h1, 'h1', config.coreStyles_h1 );
      addButtonCommand( 'BlockH2', lang.h2, 'h2', config.coreStyles_h2 );
      addButtonCommand( 'BlockH3', lang.h3, 'h3', config.coreStyles_h3 );
      addButtonCommand( 'BlockH4', lang.h4, 'h4', config.coreStyles_h4 );
      addButtonCommand( 'BlockH5', lang.h5, 'h5', config.coreStyles_h5 );
      addButtonCommand( 'BlockH6', lang.h6, 'h6', config.coreStyles_h6 );


      editor.setKeystroke( [
         [ VED.CTRL + 66 /*B*/, 'bold' ],
         [ VED.CTRL + 73 /*I*/, 'italic' ],
         [ VED.CTRL + 85 /*U*/, 'underline' ]
         ] );
   }
});

// Basic Inline Styles.
VED.config.coreStyles_bold = { element: 'strong', overrides: 'b' };
VED.config.coreStyles_italic = { element: 'em', overrides: 'i' };
VED.config.coreStyles_underline = { element: 'u' };
VED.config.coreStyles_strike = { element: 's', overrides: 'strike' };
VED.config.coreStyles_subscript = { element: 'sub' };
VED.config.coreStyles_superscript = { element: 'sup' };

// Basic block styles
VED.config.coreStyles_h1 = { element: 'h1' };
VED.config.coreStyles_h2 = { element: 'h2' };
VED.config.coreStyles_h3 = { element: 'h3' };
VED.config.coreStyles_h4 = { element: 'h4' };
VED.config.coreStyles_h5 = { element: 'h5' };
VED.config.coreStyles_h6 = { element: 'h6' };





